package com.cml.dm.admin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.cml.dm.admin.entity.DmExeLogger;
import com.cml.dm.admin.entity.DmMetadata;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DmMetadataMapper  extends BaseMapper<DmMetadata> {
    @Update("CREATE TABLE `dm_metadata`  (\n" +
            "  `id` bigint NOT NULL AUTO_INCREMENT,\n" +
            "  `task_id` varchar(32) NULL,\n" +
            "  `first` varchar(32) NULL,\n" +
            "  `node_id` varchar(32) NULL,\n" +
            "  `table` varchar(32) NULL,\n" +
            "  `org_id` varchar(32) NULL,\n" +
            "  `sharding_column` varchar(32) NULL,\n" +
            "  `pk` varchar(32) NULL,\n" +
            "  `sort_field` varchar(32) NULL,\n" +
            "  `limit` int NULL,\n" +
            "  `thread_num` int NULL,\n" +
            "  `lazy` int NULL,\n" +
            "  `join_up_pk_node` varchar(32) NULL,\n" +
            "  `join_node_id` varchar(32) NULL,\n" +
            "  `interceptor` varchar(32) NULL,\n" +
            "  `next` varchar(32) NULL,\n" +
            "  `backup_sql` text NULL,\n" +
            "  `recovery_sql` text NULL,\n" +
            "  `version` double NULL,\n" +
            "  PRIMARY KEY (`id`)\n" +
            ");")
    void createNewTable();

    @Insert("<script>" +
            "insert into asset_card (`task_id`,`first`,`node_id`,`table`,`org_id`,`pk`,`sort_field`,`limit`,`thread_num`,`lazy`,`join_up_pk_node`,`interceptor`,`next`,`backup_sql`,`recovery_sql`,`version`,`join_node_id`) " +
            "values " +
            "<foreach collection ='list' item='item' separator =','> " +
            "  (#{item.taskID}, #{item.first}, #{item.nodeId}, #{item.table}, #{item.orgId}, #{item.pk}, #{item.sortField}, #{item.limit}, #{item.threadNum}, #{item.lazy}, #{item.joinUpPkNode}, #{item.interceptor}, #{item.next}, #{item.backupSql}, #{item.recoverySql}, #{item.version}, #{item.joinNodeId}) " +
            " </foreach > " +
            "</script>"
            )
    void insertBatch(@Param("list")List<DmMetadata> metadataList);
}
